package com.sword.erp.stock.interfaces.api;

import com.sword.erp.stock.model.Stock;
import com.sword.erp.stock.service.StockService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 库存接口
 * @author sword
 * @date 2021/10/10 14:16
 */
@RestController
@Slf4j
@RequiredArgsConstructor
public class StockApi {
    /**
     * 库存服务
     */
    private final StockService stockService;

    /**
     * 减少库存
     * @return java.lang.String
     * @author sword
     * @date 2021/10/10 14:17
     */
    @GetMapping("/reduce")
    public String reduceStock() {
        log.info("库存减少1，还剩{}", stockService.reduceStock());
        return "success";
    }

    @GetMapping("/testJavaBeanToRedis")
    public Stock testJavaBeanToRedis() {
        return stockService.testJavaBeanToRedis();
    }

    @GetMapping("/testJavaBeanToRedisByKey")
    public Stock testJavaBeanToRedisByKey() {
        return stockService.testJavaBeanToRedisByKey("sword");
    }

    @GetMapping("/testJavaBeanListToRedis")
    public List<Stock> testJavaBeanListToRedis() {
        return stockService.testJavaBeanListToRedis();
    }
}
